#pragma once

#include <string>
using std::string;

class Connection
{
public:
	Connection(int sock = -1, string localIp = "", int localPort = 0, 
		string remoteIp = "", int remotePort = 0);
	~Connection(void);

	bool Write(char* buffer, int offset, int length);
	int Read(char* buffer, int offset, int length);
	bool BeginRead(char* buffer, int offset, int length, void (*completeHandler)(void));
	int EndRead();
	string GetErrorMessage();
	void Dispose();

	bool IsValid();
	string GetLocalIp();
	string GetRemoteIp();
	int GetLocalPort();
	int GetRemotePort();

private:
	int _sock;
	string _errorMessage;
	string _localIp;
	string _remoteIp;
	int _localPort;
	int _remotePort;
	

	char *_readBuf;
	int _readOffset;
	int _readLength;
	int _readBytes;
	void (*readComplete)(void);
	void readThread(void* arg);
};